package com.konsung.ksdc.manager.community;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

import com.konsung.ksdc.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 简单通用WebView展示页
 *
 * Created by andy on 2017/3/13.
 */

public class SimpleWebViewActivity extends Activity {
    // intent参数，用于取调用者传过来的Web url
    public static final String PARAMS_URL = "url";

    @Bind(R.id.iv_back)
    ImageView ivBack;
    @Bind(R.id.wv_explore)
    WebView wvExplore;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple_webview);
        ButterKnife.bind(this);

        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        String url = getIntent().getStringExtra(PARAMS_URL);
        wvExplore.loadUrl(url);
        WebSettings settings = wvExplore.getSettings();
        settings.setJavaScriptEnabled(true);
        wvExplore.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) { //
                // 重写此方法表明点击网页里面的链接还是在当前的webview里跳转，不跳到浏览器那边
                view.loadUrl(url);
                return true;
            }
        });
    }
}
